<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"></view>
      <!-- <view class="jtop_l2" @tap="navigateBack">取消</view> -->
      <view class="jtop_c">选择成员</view>
      <view class="jtop_r" @tap="navigateBack2"
        >确定({{ jqeditry.length }})</view
      >
    </view>
    <view class="tophr"></view>
    <uni-search-bar
      placeholder="搜索"
      @confirm="search"
      class="ss"
      bgColor="#ffffff"
    ></uni-search-bar>

    <!-- 无内容 -->
    <view class="no" v-if="!nodata">
      <view class="no_t">
        <image
          src="../../static/img/index/2/ic_Material procurement_grey.png"
        ></image>
      </view>
      <view class="no_c">
        暂无通讯录
      </view>
    </view>

    <view v-if="nodata">
      <view class="dus_boxs">
        <view
          class="dus_box"
          @click="pc(index)"
          v-for="(item, index) in items"
          :key="item.id"
        >
          <image
            :src="
              item.jqedit == true
                ? '../../static/img/doc/ic_check_press.png'
                : '../../static/img/doc/ic_check_normal.png'
            "
            class="dus_box_s dus_box_sx"
          ></image>

          <image
            :src="
              item.avatar ? item.avatar : '../../static/img/Default_avatar.png'
            "
            class="dus_box_tx"
            @tap="tel_more(item.id)"
          ></image>

          <view class="dus_box_l">
            <text class="dus_box_lt">{{
              item.name ? item.name : item.userInfoResponse.realName
            }}</text>
            <text class="dus_box_lf">{{ item.duty }}</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 	<view class="dus_boxs">
			<view class="dus_box">
				<image src="../../static/img/doc/ic_check_press.png"  class="dus_box_s"></image>
				<image src="../../static/img/jhead_portrait.png" class="dus_box_tx" ></image>
				<view class="dus_box_l">
					<text class="dus_box_lt">小布衣</text>
					<text class="dus_box_lf">底层搬砖工</text>
				</view>
			</view>
			<view class="dus_box">
				<image src="../../static/img/doc/ic_check_normal.png"  class="dus_box_s"></image>
				<image src="../../static/img/jhead_portrait.png" class="dus_box_tx" ></image>
				<view class="dus_box_l">
					<text class="dus_box_lt">小布衣</text>
					<text class="dus_box_lf">底层搬砖工</text>
				</view>
			</view>
			<view class="dus_box">
				<image src="../../static/img/doc/ic_check_normal.png"  class="dus_box_s"></image>
				<image src="../../static/img/jhead_portrait.png" class="dus_box_tx" ></image>
				<view class="dus_box_l">
					<text class="dus_box_lt">小布衣</text>
					<text class="dus_box_lf">底层搬砖工</text>
				</view>
			</view>
		</view> -->

    <view class="dcf" v-if="jqeditrytx.length > 1">
      <view class="" v-for="(item, index) in jqeditrytx" :key="index">
        <image :src="item" class="dcf_tx"></image>
      </view>

      <!-- <text class="dcf_t" @tap="navigateBack2">确定({{jqeditry.length}})</text> -->
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState } from 'vuex';

export default {
  computed: mapState(['forcedLogin', 'hasLogin', 'userName']),

  data() {
    return {
      repeat_click: true,
      ashowpop: false,
      ashowpop_jrename: false,
      ashowpop_jdel: false,
      ashowpopT: false,
      bj: false,
      yd: false,
      nodata: false,
      items: [],
      jqeditid: '',
      ashowpop2: false,
      projectId: uni.getStorageSync('dqfull_name').id,
      jqeditry: [],
      jqeditrytx: [],
      jedittx: false,
    };
  },

  onShow() {
    if (uni.getStorageSync('jqeditry') != '[]') {
      this.jqeditry = uni.getStorageSync('jqeditry');
      if (uni.getStorageSync('jqeditrytx')) {
        this.jqeditrytx = uni.getStorageSync('jqeditrytx');
      } else {
        console.log(111111);
        this.jedittx = true;
      }
    }

    this.lb();
  },

  methods: {
    pc(e) {
      console.log(e);
      this.items[e]['jqedit'] = !this.items[e]['jqedit'];

      var bh = this.jqeditry.indexOf(this.items[e].id);

      if (bh == -1) {
        this.jqeditry.unshift(this.items[e].id);

        if (this.items[e].avatar) {
          this.jqeditrytx.unshift(this.items[e].avatar);
        } else {
          this.jqeditrytx.unshift('../../static/img/Default_avatar.png');
        }
      } else {
        var ax = this.jqeditry;
        ax.splice(bh, 1);
        this.jqeditry = ax;

        var axtx = this.jqeditrytx;
        axtx.splice(bh, 1);
        this.jqeditrytx = axtx;
      }

      console.log(this.jqeditry);
      console.log(this.jqeditrytx);

      uni.setStorageSync('jqeditry', this.jqeditry);
      uni.setStorageSync('jqeditrytx', this.jqeditrytx);

      // uni.makePhoneCall({
      // phoneNumber: e,
      //  });
    },
    search(e) {
      console.log(e);
      this.lb(e.value);
    },

    lb(e) {
      var jd = {
        page: 1,
        size: 1000000,
      };

      if (e) {
        jd.key = e;
      }

      // 获取列表信息
      request({
        url: `/ucenter/corp-user/list`,

        data: {
          corpId: uni.getStorageSync('user').corpBaseInfoResponse.id,
        },
        method: 'GET',
        // data: jd,

        success: res => {
          console.log('项目dd列表', res);
          console.log(res.data.data.length);
          if (res.data.success == true) {
            if (res.data.data.length > 0) {
              var cc = res.data.data;
              for (var i = 0; i < cc.length; i++) {
                cc[i].jqedit = false;
              }

              var dd = uni.getStorageSync('jqeditry');
              if (dd) {
                for (var j = 0; j < dd.length; j++) {
                  for (var x = 0; x < cc.length; x++) {
                    if (cc[x].id == dd[j]) {
                      cc[x].jqedit = true;
                    }
                  }
                }
              }

              if (this.jedittx) {
                console.log(22222);
                var ee = [];

                for (var j = 0; j < dd.length; j++) {
                  for (var x = 0; x < cc.length; x++) {
                    if (cc[x].id == dd[j]) {
                      if (cc[x].avatar) {
                        ee.push(cc[x].avatar);
                      } else {
                        ee.push('../../static/img/Default_avatar.png');
                      }
                    }
                  }
                }
                console.log('3333', ee);
                this.jqeditrytx = ee;
              }

              this.items = cc;

              console.log(this.items);

              this.nodata = true;
            } else {
              this.items = '';
              this.dqfull_name = '';
              this.nodata = false;
            }
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    navigateBack() {
      if (!this.jedittx) {
        uni.removeStorageSync('jqeditry');
        uni.removeStorageSync('jqeditrytx');
      }

      uni.navigateBack();
    },

    navigateBack2() {
      uni.navigateBack();
    },

    tel_more(e) {
      var jc = this.items.filter(item => {
        return item.id == e;
      });

      console.log(jc);

      uni.setStorageSync('jc', jc[0]);

      uni.navigateTo({
        url: '../main/tel_more',
      });
    },
    add() {
      uni.navigateTo({
        url: '../main/tel_add',
      });
    },
  },
};
</script>

<style>
.no {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 400rpx 0 0;
}
.no_t {
  width: 200rpx;
  height: 200rpx;
  display: block;
  float: left;
  margin: 0 275rpx;
  background: #ffffff;
  border-radius: 200rpx;
}
.no_t image {
  width: 140rpx;
  height: 140rpx;
  display: block;
  float: left;
  margin: 30rpx;
}
.no_c {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 30rpx 0 50rpx;
  color: #666666;
  font-size: 32rpx;
  line-height: 40rpx;
  text-align: center;
}
.no_f {
  width: 460rpx;
  height: 94rpx;
  line-height: 94rpx;
  background: #256aff;
  border-radius: 10rpx;
  display: block;
  float: left;
  margin: 0 145rpx;
  color: #ffffff;
  font-size: 36rpx;
  text-align: center;
}
.no_f:active {
  background: linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.199437),
      rgba(0, 0, 0, 0.199437)
    ),
    #256aff;
}

.tophr {
  width: 100%;
  height: 88rpx;
}
.uni-searchbar {
  box-shadow: none;
}
.tc {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  display: block;
}
.dus {
  width: 100%;
  height: 90rpx;
  display: block;
  float: left;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  background: #ffffff;
}
.dusl {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 21rpx 22rpx 21rpx 30rpx;
}
.dusc {
  width: auto;
  height: 42rpx;
  font-size: 34rpx;
  line-height: 42rpx;
  color: #000000;
  display: block;
  float: left;
  margin: 24rpx 0;
}
.dusr {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 33rpx 30rpx 0 0;
}
.dus_t {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #999999;
  border-bottom: 1px solid #dddddd;
  padding: 20rpx 30rpx;
  box-sizing: border-box;
}
.dus_tl {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #999999;
  padding: 4rpx 30rpx;
  box-sizing: border-box;
}
.dus_boxs {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  background: #ffffff;
}
.dus_box {
  width: 720rpx;
  margin: 0 0 0 30rpx;
  height: 120rpx;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
}
.dus_boxs .dus_box:last-child {
  border: 0;
}
.dus_box_s {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 36rpx 30rpx 0 0;
}
.dus_box_s {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 36rpx 30rpx 0 0;
}
.dus_box_tx {
  width: 84rpx;
  height: 84rpx;
  display: block;
  float: left;
  margin: 18rpx 20rpx 0rpx 0;
}
.dus_box_l {
  width: 500rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0rpx 0 0rpx 0;
}
.dus_box_lt {
  width: 100%;
  height: 42rpx;
  display: block;
  float: left;
  margin: 18rpx 0 10rpx 0;
  font-size: 34rpx;
  line-height: 42rpx;
  color: #000000;
}
.dus_box_lf {
  width: 100%;
  height: 32rpx;
  display: block;
  float: left;
  margin: 0rpx 0 0rpx 0;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #999999;
}
.dus_box_sx {
  /* opacity: .5; */
}

.dcf {
  width: 100%;
  height: 120rpx;
  display: block;
  float: left;
  position: fixed;
  left: 0;
  bottom: 0;
  background: #ffffff;
  box-shadow: inset 0px 1px 0px #dddddd;
  z-index: 1000;
  padding: 18rpx 30rpx;
  box-sizing: border-box;
}
.dcf_tx {
  width: 84rpx;
  height: 84rpx;
  display: block;
  float: left;
  margin: 0rpx 20rpx 0rpx 0;
}
.dcf_t {
  width: auto;
  height: 84rpx;
  line-height: 84rpx;
  display: block;
  float: right;
  margin: 0rpx 0rpx 0rpx 0;
  font-size: 36rpx;
  color: #256aff;
}

.index {
  background: rgb(242, 242, 242);
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_l2 {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #256aff;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}

.jtop_r {
  width: auto;
  height: 88rpx;
  display: block;
  float: right;
  margin: 0rpx 20rpx 0 0;
  line-height: 88rpx;
  font-size: 32rpx;
  color: #000000;
  color: #256aff;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}

.uni-searchbar {
  background: rgb(242, 242, 242);
}
.index .uni-searchbar__box {
  background: #ffffff !important;
}
</style>
